package com.changgou.config;

import org.activiti.engine.*;
import org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.activiti.engine.repository.DeploymentBuilder;
import org.activiti.spring.SpringAsyncExecutor;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.AbstractProcessEngineAutoConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.transaction.PlatformTransactionManager;

import javax.annotation.PostConstruct;
import javax.sql.DataSource;
import java.io.IOException;

//@Configuration
public class ActivitiDatasourceConfig  {

//    @Autowired
//    private DataSource dataSource;
//
//    @Autowired
//    private ResourcePatternResolver resourceLoader;
//
//    /**
//     * 初始化配置，将创建28张表
//     * @return
//     */
//    @Bean
//    public StandaloneProcessEngineConfiguration processEngineConfiguration() {
//        StandaloneProcessEngineConfiguration configuration = new StandaloneProcessEngineConfiguration();
//        configuration.setDataSource(dataSource);
//        configuration.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);
//        configuration.setAsyncExecutorActivate(false);
//        return configuration;
//    }
//
//    @Bean
//    public ProcessEngine processEngine() {
//        return processEngineConfiguration().buildProcessEngine();
//    }
//
//    @Bean
//    public RepositoryService repositoryService() {
//        return processEngine().getRepositoryService();
//    }
//
//    @Bean
//    public RuntimeService runtimeService() {
//        return processEngine().getRuntimeService();
//    }
//
//    @Bean
//    public TaskService taskService() {
//        return processEngine().getTaskService();
//    }
//
//    @Bean
//    public HistoryService historyService() {
//        return processEngine().getHistoryService();
//    }
//
//    /**
//     * 部署流程
//     * @throws IOException
//     */
//    @PostConstruct
//    public void initProcess() throws IOException {
//        DeploymentBuilder deploymentBuilder= repositoryService().createDeployment();   deploymentBuilder.enableDuplicateFiltering().addClasspathResource("projectDeclareProcess.bpmn").name("projectDeclareProcess").deploy();
//        Resource resource1 = resourceLoader.getResource("classpath:/processes/testbp.bpmn"); //加载流程图资源文件
//        deploymentBuilder.enableDuplicateFiltering().addInputStream(resource1.getFilename(), resource1.getInputStream()).name("myProcess_01").deploy(); //按流程id部署
//    }

}
